import { _addressList } from "../../../../service/api";

Page({
  data: {
    addressList: [],
  },
  onShow: function (options) {
    this.getAddressList();
  },
  async getAddressList() {
    const res = await _addressList();
    this.setData({ addressList: res });
  },
  handleSelectAddress(e) {
    const { addressId } = e.currentTarget.dataset;
    wx.setStorageSync("addressId", addressId);
    wx.redirectTo({
      url: "/pages/shopping/confirm_order/comfirm_order",
    });
  },
  handleaddNewAddress() {
    wx.navigateTo({
      url: "/pages/shopping/new_address/new_address",
    });
  },
  handleEditAddress(e) {
    const { addressId } = e.currentTarget.dataset;
    wx.navigateTo({
      url: "/pages/shopping/new_address/new_address?id=" + addressId,
    });
  },
});
